
CPPPARAMS= -m32 -Iinclude -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = obj/loader.o \
		  obj/kernel.o \
		  obj/gdt.o \
		  obj/syscallhandle.o \
		  obj/hardwarecommunication/port.o \
		  obj/hardwarecommunication/interrupts.o \
		  obj/hardwarecommunication/pci.o \
		  obj/interruptstubs.o \
		  obj/driver/keyboard.o \
		  obj/driver/vga.o \
		  obj/driver/ata.o \
		  obj/gui/widget.o \
		  obj/gui/window.o \
		  obj/gui/desktop.o \
		  obj/memory/memorymanagement.o \
		  obj/driver/amd_am79c973.o \
		  obj/common/common.o \
		  obj/driver/mouse.o \
		  obj/driver/driver.o \
		  obj/multitasking.o \
		 

obj/%.o: src/%.s
	mkdir -p $(@D)
	as $(ASPARAMS) -o $@ $<

obj/%.o: src/%.cpp
	mkdir -p $(@D)
	g++ $(CPPPARAMS) -o $@ -c $<



mykernel.bin: linker.ld $(objects)
	ld $(LDPARAMS) -T $< -o $@ $(objects)
install: mykernel.bin
	sudo cp $< /boot/mykernel.bin


mykernel.iso : mykernel.bin
	mkdir iso
	mkdir iso/boot
	mkdir iso/boot/grub
	cp $< iso/boot/
	echo 'set timeout=0' > iso/boot/grub/grub.cfg
	echo 'set default=0' >> iso/boot/grub/grub.cfg
	echo '' >> iso/boot/grub/grub.cfg
	echo 'menuentry "My Operator System" {' >> iso/boot/grub/grub.cfg
	echo '    multiboot /boot/mykernel.bin' >> iso/boot/grub/grub.cfg
	echo '    boot' >> iso/boot/grub/grub.cfg
	echo '}'>> iso/boot/grub/grub.cfg
	grub-mkrescue --output=$@ iso
	rm -rf *.o *.bin
	rm -rf iso
	# qemu-system-x86_64  mykernel.iso
clean :
	rm -rf obj *.bin
	rm -rf iso
run: mykernel.iso
	# (killall VirtualBox) || true
	# VirtualBox --startvm "mos" &


# clean:
	# rm -rf $(objects) mykernel.bin mykernel.iso
	
